/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul></ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>签约申请列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-select v-model="store_grade" size="small" clearable placeholder="所属等级">
          <el-option
            v-for="item in storeGrade"
            :key="item.sg_id"
            :label="item.sg_name"
            :value="item.sg_id"
          ></el-option>
        </el-select>
        <el-select v-model="store_class" size="small" clearable placeholder="店铺类别">
          <el-option
            v-for="item in storeClass"
            :key="item.sc_id"
            :label="item.sc_name"
            :value="item.sc_id"
          ></el-option>
        </el-select>
        <el-input
          class="searchinput"
          v-model="seller_name"
          size="small"
          placeholder="店主名称"
          clearable
        />
        <el-input
          class="searchinput"
          v-model="store_name"
          width="10"
          size="small"
          placeholder="店铺名称"
          clearable
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox" v-if="tableData">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="等级名称" prop="re_grade_name" width="100"></el-table-column>
        <el-table-column label="店铺名称" prop="re_store_name" width="150"></el-table-column>
        <el-table-column label="申请时间" prop="re_create_time_desc" width="150"></el-table-column>
        <el-table-column
          label="收费标准（元/年）"
          prop="re_grade_price"
          width="150"
          :formatter="gradeToFixed"
        ></el-table-column>
        <el-table-column label="续签时长（年）" prop="re_year" width="120"></el-table-column>
        <el-table-column
          label="付款金额（年）"
          prop="re_pay_amount"
          width="120"
          :formatter="payAmountToFixed"
        ></el-table-column>
        <el-table-column
          label="续签起止有效期"
          prop="re_start_to_end_time_desc"
          width="200"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column label="状态" prop="re_state_desc" width="100"></el-table-column>
        <el-table-column label="付款凭证" width="150">
          <template scope="scope">
            <img :src="scope.row.re_pay_cert" width="60" height="40" />
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
			  <el-button-group>
				  <el-button size="small" @click="detail(scope.row.re_id)" icon="el-icon-zoom-in">查看</el-button>
				  <el-button size="small" @click="remove(scope.row.re_id)" icon="el-icon-delete">删除</el-button>
			  </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import {
  getStoreReopenPage,
  deleteStoreReopen,
  getStoreGradeList,
  getStoreClass
} from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10,
      store_grade: null,
      store_class: null,
      seller_name: null,
      store_name: null,
      storeGrade: [],
      storeClass: []
    };
  },
  components: {},
  created() {
    this.getPage();
    this.getStoreGradeList();
    this.getStoreClass();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      getStoreReopenPage({
        grade_id: this.store_grade,
        sc_id: this.store_class,
        seller_name: this.seller_name,
        store_name: this.store_name,
        p: this.currentPage,
        size: this.pageSize
      }).then(function(res) {
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    refresh() {
      this.getPage();
      this.$message({
        type: "success",
        message: "刷新成功！"
      });
    },
    detail(id) {
      this.$router.push({
        name: "reopen",
        params: {
          id: id,
          currentPage: this.currentPage
        }
      });
    },
    remove(id) {
      var that = this;
      this.$confirm("确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteStoreReopen(id).then(function(res) {
            if (res.msg) {
              that.$message.error({
                message: res.msg
              });
            } else {
              that.getPage();
              that.$message.success("删除成功!");
            }
          });
        })
        .catch(() => {
          that.$message.info({
            message: "已取消删除"
          });
        });
    },
    getStoreGradeList() {
      var that = this;
      getStoreGradeList().then(function(res) {
        that.storeGrade = res;
      });
    },
    getStoreClass() {
      var that = this;
      getStoreClass().then(function(res) {
        that.storeClass = res;
      });
    },
    gradeToFixed(row) {
      return parseFloat(row.re_grade_price).toFixed(2);
    },
    payAmountToFixed(row) {
      return parseFloat(row.re_pay_amount).toFixed(2);
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}
</style>
